package com.azzcs.reactive.rxjava;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Observable;
import org.junit.jupiter.api.Test;

/**
 * @Author: wzg
 * @Date: 2021/5/13 上午6:16
 */

public class Demo {

    @Test
    public void test1(){
        Flowable.just("Hello world").subscribe(System.out::println);
        Flowable<Integer> flow = Flowable.range(1, 5)
                .map(v -> v * v)
                .filter(v -> v % 3 == 0);
        flow.subscribe(System.out::print);


        Observable.create(emitter->{
            while (!emitter.isDisposed()) {
                long time = System.currentTimeMillis();
                emitter.onNext(time);
                if (time % 2 != 0) {
                    emitter.onError(new IllegalStateException("Odd millisecond!"));
                    break;
                }
            }
        }).subscribe(System.out::print,Throwable::printStackTrace);
        
    }
}
